package demandsystem

const (
	URL_Type_4K    = "2160"
	URL_Type_2K    = "1440"
	URL_Type_1080P = "1080"
	URL_Type_720P  = "720"

	URL_ERROR_OSS      int16 = -2 //url oss上传错误
	URL_ERROR_FFMPEG   int16 = -3 //url ffmpeg切片错误
	URL_ERROR_FILEPATH int16 = -4 //url 文件路径错误
	URL_ERROR_FILEINFO int16 = -5 //url 获取文件信息错误

	RESOURCES_ERROR_OSS      int16 = -2 //源文件 oss上传错误
	RESOURCES_ERROR_COMPRESS int16 = -3 //源文件 视频压缩错误
	RESOURCES_ERROR_FILEPATH int16 = -4 //源文件 路径错误
	RESOURCES_ERROR_FILEINFO int16 = -5 //源文件 信息错误
)

type FileInfo struct {
	FileSize uint64 `json:"file_size" form:"file_size"`
	FileName string `gorm:"type:varchar(255);index" json:"file_name" form:"file_name" validate:"required,min=2,max=255"`
	FileHash string `gorm:"type:varchar(255);index" json:"file_hash" form:"file_hash"`
}

type CompressInfo struct {
	CompressClass      uint8  `gorm:"default:0" json:"compress_class" form:"compress_class" validate:"min=0,max=4"`             //压缩等级,0-4,0=不压缩
	AudioCompressClass uint8  `gorm:"default:0" json:"audio_compress_class" form:"audio_compress_class" validate:"min=0,max=2"` //音频压缩等级,0-2,0=不压缩
	CompressFileSize   uint64 `json:"compress_file_size"`
}

type VideoInfo struct {
	VideoWidth    uint64 `json:"video_width" form:"video_width"`
	VideoHeight   uint64 `json:"video_height" form:"video_height"`
	VideoDuration string `gorm:"type:varchar(255);" json:"video_duration" form:"video_duration"` //视频长度:秒
}

type Resource struct {
	ResourcesID string `gorm:"type:varchar(255);primaryKey;auto_increment:false" json:"resources_id" form:"resources_id"`
	Name        string `gorm:"type:varchar(255);index" json:"resource_name" form:"resource_name" validate:"required,min=2,max=255"`
	Description string `gorm:"type:text;" json:"resource_description" form:"resource_description" validate:"max=255"`

	FileInfo
	VideoInfo
	CompressInfo

	Status      int16     `gorm:"default:0" json:"status" form:"status"` //资源状态: 0=已提交表单、1=已经上传文件、小于0=错误
	PlayUrlList []PlayUrl `gorm:"foreignKey:ResourcesID;references:ResourcesID" json:"play_url_list"`

	DepartmentID uint   `gorm:"default:0;index" json:"department_id" form:"department_id"`
	RegionCode   string `gorm:"type:varchar(255);index" json:"region_code" form:"region_code" validate:"required"`
	User         string `gorm:"type:varchar(255);index" json:"user" form:"user" validate:"max=255"`
	Category     string `gorm:"type:varchar(255);index" json:"category" form:"category" validate:"max=255"`
	Channel      string `gorm:"type:varchar(255);index" json:"channel" form:"channel" validate:"required,min=2,max=255"`
	Cover        string `gorm:"type:varchar(255);" json:"cover"`
	PlayNum      uint32 `gorm:"default:0" json:"play_num" form:"play_num"`

	ResourcesType uint16 `gorm:"default:0" json:"type" form:"type"`                   //资源类型0=普通
	OCode         string `gorm:"type:varchar(255);index" json:"o_code" form:"o_code"` //项目代码
	IscID         string `gorm:"type:varchar(255);index" json:"isc_id" form:"isc_id"` //isc_id

	CreatedTime int64 `gorm:"index" json:"created_time"`
	TopLevel    uint  `json:"-"`
}

// 播放地址
type PlayUrl struct {
	ResourcesID    string   `gorm:"type:varchar(255);index" json:"-"`
	Resources      Resource `gorm:"foreignKey:ResourcesID;references:ResourcesID" json:"-"`
	NodeID         uint     `gorm:"index" json:"-"`
	NodeRegionCode string   `gorm:"type:varchar(255);index" json:"node_region_code"`
	//URL状态：-1=未开始、1-100=切片进度、100=切片完成、100-200上传进度、200=上传完成、小于0=错误
	Url4k          string `gorm:"column:url_4k;type:varchar(255)" json:"url_4k"`
	Url4kStatus    int16  `gorm:"column:url_4k_status;default:-1" json:"url_4k_status"`
	Url2k          string `gorm:"column:url_2k;type:varchar(255)" json:"url_2k"`
	Url2kStatus    int16  `gorm:"column:url_2k_status;default:-1" json:"url_2k_status"`
	Url1080p       string `gorm:"column:url_1080p;type:varchar(255)" json:"url_1080p"`
	Url1080pStatus int16  `gorm:"column:url_1080p_status;default:-1" json:"url_1080p_status"`
	Url720p        string `gorm:"column:url_720p;type:varchar(255)" json:"url_720p"`
	Url720pStatus  int16  `gorm:"column:url_720p_status;default:-1" json:"url_720p_status"`
}

// 小文件记录
type OssFileInfo struct {
	NodeID      uint     `gorm:"index" json:"node_id"`
	ResourcesID string   `gorm:"type:varchar(255);index"`
	Resources   Resource `gorm:"foreignKey:ResourcesID;references:ResourcesID" json:"-"`
	Url         string   `gorm:"type:varchar(255);index"`
	Resolution  string   `gorm:"type:varchar(255);index"`
	FileSize    uint64   `json:"file_size"`
	VolumeNum   uint64   `json:"volume_num"`
}

// 节点
type OnDemandNode struct {
	NodeRegionCode string  `gorm:"type:varchar(255);intex" json:"node_region_code"` //节点地区
	NodeHost       string  `gorm:"type:varchar(255);intex" json:"node_host"`        //节点IP
	NodePort       string  `gorm:"type:varchar(255);" json:"node_port"`             //节点端口
	MaxVolume      uint64  `json:"max_volume"`                                      //最大使用容量(字节)
	UsedVolume     uint64  `gorm:"default:0"`                                       //已经使用容量(字节)
	PercentVolume  float32 `gorm:"default:0"`                                       //容量占比%
}
type Region struct {
	Code string `gorm:"type:varchar(255);intex" json:"code"`
	Name string `gorm:"type:varchar(255);" json:"name"`
}

type Department struct {
	ID         uint   `gorm:"primarykey" json:"department_id"`
	RegionCode string `gorm:"type:varchar(255);intex" json:"region_code"`
	Name       string `gorm:"type:varchar(255);" json:"department_name"`
}

type Router struct {
	// DepartmentID uint       `json:"-"`
	// Department   Department `json:"department"`
	OrginRegionCode string `gorm:"type:varchar(255);intex" json:"orgin_region_code"`
	NodeRegionCode  string `gorm:"type:varchar(255);intex" json:"node_region_code"`
}

// 源文件
type OrginFileInfo struct {
	ResourcesID string   `gorm:"type:varchar(255);primarykey;auto_increment:false" json:"-"`
	Resources   Resource `gorm:"foreignKey:ResourcesID;references:ResourcesID" json:"-"`
	NodeID      uint     `gorm:"index" json:"-"`
	RegionCode  string   `gorm:"type:varchar(255);" json:"node_region_code"`
	Url         string   `gorm:"type:varchar(255);" json:"file_url"`
	VolumeNum   uint64   `json:"-"`
}
